home *** CD-ROM | disk | FTP | other *** search
-
-
- Masterclass
-
-
- Using ARexx with other programs can add new features and
- automate existing ones. Here's how...
-
-
-
- We've already seen that ARexx is a powerful and elegant
- programming language in its own right. However, the real
- power of ARexx comes when it is combined with other
- programs.
-
- Remember that the Amiga can multitask many applications at
- once with no effort, and so it's possible to run, say a
- graphics program, and whilst that is happening start an
- ARexx script running. It's also possible to make use of
- specific features of the graphics program from the ARexx
- script. Here's how.
-
- In order for an application program to be used with ARexx,
- it must have what is referred to as an "ARexx Port". This
- means that when the operating systems sends a command to a
- certain location, the application program will recognise it.
- It's up the the application to deal with the ARexx command,
- and perform an action or return a value to the ARexx script.
- For example, an ARexx paint program may accept commands such
- as "Plot" or "Circle" and perform a suitable action on the
- screen.
-
- Here's an example of how you would use ARexx to work with
- another program. In this case we'll use AdPro (the Art
- Department Professional) as our ARexx compatible application
- program.
-
- Remember that an ARexx program or script is simply a plain
- text file, and so it can be created with any text editor and
- saved to disk or to RAM disk. Most programs have there own
- little foibles when it comes to dealing with ARexx, and
- AdPro is no exception. If you create the script and save it
- to the directory ADPROSCRIPTS: with a filename such as
- "f8.adpro", when you press the Funtion8 key AdPro will run
- the scipt. This is very useful, as it saves you from opening
- a Shell window and typing "rx myprogram.rexx" everytime --
- although occasionally this is exactly what you want to do,
- especially in long batch processing jobs.
-
- Here's what a sample ARexx script looks like, line by line.
- ARexx works by allowing the host programs to
- make new functions available, and so some of the commands
- don't look familiar and certainly won't work with other host
- programs. This is simply because they are AdPro commands,
- not ARexx functions.
-
- (Note to art people: please include the lines between
- "%" in a different font, and remove the "%"s. I'm trying to
- add comments to the listing to explain each line, so please
- make it clear the text % between markers like this % is not
- part of the listing, but only explanitory text which should
- not be typed in.)
-
-
-
-
-
- Example Listing
-
-
-
- /*
- Example Program using AdPro
- */
-
-
- % All ARexx programs must start with a comment %
-
- ADDRESS "ADPro"
-
- % This tells the ARexx system which host program to use.
- This is the special Arexx "Port name" you hear about. If you
- get it wrong, the script won't work as the AdPro commands
- won't be found. You must get the upper and lower case
- letters correct too! %
-
- OPTIONS RESULTS
-
- % this is a special ARexx command to inform the system that
- some commands will be returning values to the script for
- processing %
-
- GETFILE
-
- % This is an ADPro command, not an ARexx command. It makes
- AdPro put up a file requestor and ask for a file from the
- user %
-
- filename = ADPRO_RESULT
-
- % This is an ARexx command -- the variable called "filename"
- is set to the value returned in the special variable called
- ADPRO_RESULT. In this case, ADPRO_RESULT will containt the
- name of the file the user selected %
-
- okay1 "File name is" filename
-
- % This is an AdPro command. Rather than use the ARexx SAY to
- print test to the Shell, this AdPro command opens a window
- on the AdPro screen and displays the text %
-
- lformat "universal"
-
- % This is an AdPro command, and it sets the loader to be
- universal i.e. automatically detect and load the file %
-
- load filename
-
- % The is an AdPro command, and it loads the file passed to
- it -- in this case the name was stored in the ARexx variable
- called "filename" %
-
- xsize
-
- % This is an AdPro command to get the width of the loaded
- image file %
-
- x=ADPRO_RESULT
-
- % This is an ARexx command to assign the width to the
- variable called "x" %
-
-
- ysize
- y=ADPRO_RESULT
-
- % As before, although this time the height %
-
- okay1 "File is " x "wide and " y "tall."
-
- % This AdPro command will print text in a box on the AdPro
- screen %
-
-
-
-
- -------------------------------------------------
-
-
- You can see there is really nothing to it, because AdPro
- does all the hard work for us. All we do is automate the
- pressing of the buttons by calling the relevant commands
- directly. The AdPro documentation includes full details of
- all the commands which are available, and many example
- script are supplied. Some of the scripts will process all
- the frames in an animation, or animate ripple effects.
- Anything which AdPro can do can be automated, which is an
- excellent way to save time.
-
- This is what "Batch processing" is all about. You set up the
- computer to repeat a task, and then you go on and do
- something else (such as going to bed) whilst it gets on with
- it. You are perform tedious operations such as loading in a
- thousand images in JPEG format, scaling them and re-saving
- them in GIF format.
-
- You can also use batch processing in a creative way: For
- example, you might want to make an animation in which the
- screen fades out and fades in -- an AdPro script can load
- each frame in turn, adust the colours and re-save it. Or you
- might want to add ripple effects as though the image was
- underwater and rain drops were falling on it. Once again, an
- ARexx script can handle all this for you.
-
- Sadly AdPro is rather hard to get hold of these days, so
- hopefully the next release of Photogenics will feature an
- ARexx port.
-
- Don't think that graphics programs are the only applications
- which benefit from ARexx. Final Writer is an superb Amiga
- "Page Processor" program, and the authors were smart enough
- to include a full ARexx port. As a result, hundreds of ARexx
- macros have been written and many are available for free
- from the Aminet (either the CDROMS or the Internet site).
- You'll find scripts which will write business letters for
- you, draw graphics, wrap text in circles and automatically
- create drop shadow effects.
-
- Advanced ARexx users can take advantage of the many
- libraries and routines available. For example, it's possible
- to create a graphical front end with gadgets, windows and
- requestors all from an ARexx script. We'll take a look at
- these next time.
-
-
-
-
-
-
-
-
-
-
-
- Box out: Speeding up Arexx programs
- -----------------------------------
-
-
- ARexx is an interpreted language, which means it is always
- going to run rather slowly. One way to speed up ARexx
- programs is to compile them, and there are one or two
- programs which will do this available. However, it's simpler
- to simply stream-line the existing script as much as
- Possible: and that is exactly what the program "RexxOpt" I
- found on Aminet does. Take a look at the following extracts
- from an ARexx script, showing before and after. Although
- this is clearly not good programming practice, it is a fair
- way to get a little extra speed from programs you have
- already written and tested. Make sure you keep a copy of the
- original though!
-
-
- BEFORE
- ------
-
- (note: please use a small tight font for the listings, it's
- not for typing in rather for demonstrating how the
- compression works!)
-
-
-
-
-
- /*
- Search for file names
- ending in #?bak, and then
- delete them if necessary.
- © John Kennedy
- */
-
- address command /* Use AmigaDOS */
-
- /* First, generate list of files & sizes */
-
- Say "Making list of all files in current directory...."
-
- 'list lformat "%p%n %l" all files > t:templist'
-
-
- /* Now, search for those ending in .bak */
-
- Say "Adding up file sizes.."
-
- infile='infile'
- outfile='outfile'
-
- total_size=0
- number=0
-
- call open(outfile,'t:report','w')
- call open(infile,"t:templist",'r')
-
- do while ~eof(infile)
- data=readln(infile)
- if data~='' then do
- parse var data namepath " " size
- if size='empty' then size=0
- test=right(namepath,4)
- if (test='.bak') then do
- total_size=total_size+size
- number=number+1
- call writeln(outfile,namepath)
- end
- end
- end
- call close(infile)
- call close(outfile)
-
-
-
- AFTER
- -----
-
- /* Optimized with RexxOpt 1.7 */
- address command;Say "Making list of all files in current
- directory....";'list lformat "%p%n %l" all files >
- t:templist';Say "Adding up file
- sizes..";infile='infile';outfile='outfile';total_size=0;numb
- er=0;call open(outfile,'t:report','w');call
- open(infile,"t:templist",'r');do while
- ~eof(infile);data=readln(infile);if data~='' then;do;parse
- var data namepath " " size;if size='empty' then
- size=0;test=right(namepath,4);if (test='.bak')
- then;do;total_size=total_size+size;number=number+1;call
- writeln(outfile,namepath);end;end;end;call
- close(infile);call close(outfile)
-
-
-
- Box out: ARexx compatible programs
- -----------------------------------
-
-
- Here is a list, by no means comprehensive, of some of the
- more popular programs to feature ARexx ports. If an
- applicate program has an ARexx Port, you can write an ARexx
- script to call various features of the application, or
- create macros for use within the program. For example, as
- both the V-Lab video digitiser and AdPro image processor
- have Arexx ports, you could write a script to grab frames
- from video, scale them, re-colour them, and save them to
- disk: all automatically.
-
-
- Ami-Back
- Disk backup and maintainance suite.
-
- AMosaic
- World Wide Web browser.
-
- AmiTCP/IP
- TCP/IP networking suite.
-
- AMOS Professional
- Programming language.
-
- Art Department Professional
- Image processor.
-
- Bars & Pipes Professional
- MIDI sequencer and multimedia authoring tool.
-
- Blitz Basic II
- Programming language.
-
- CanDo
- Programming language and multimedia authoring tool.
-
- CygnusEd Professional
- Text editor
-
- DeliTracker
- MOD player
-
- Directory Opus
- File management.
-
- DirWorks
- File management.
-
- Distant Suns
- Astronomy program.
-
- Final Copy
- Page publisher.
-
- GPFax
- Use modem as fax machine.
-
- ImageFX
- Image processor.
-
- LightWave
- Image renderer.
-
- MainActor
- Animation player.
-
- Maple
- Mathematics engine.
-
- Music-X 2
- MIDI sequencer.
-
- NComm
- Terminal emulator.
-
- Quarterback
- Disk backup and maintainance suite.
-
- Real3D
- Image renderer.
-
- SnoopDOS
- System monitor.
-
- Spot
- FidoNet mail manager.
-
- Termite
- Terminal emulator.
-
- Thor
- Mail/news manager.
-
- TrapDoor
- FidoNet mailer.
-
- TypeSmith
- Font editor.
-
- VistaPro
- Landscape generator.
-
- V-Lab
- Video digitiser.
-
- Xi-Paint
- Paint package.
-
-
-
- captions
- --------
-
-
- may1.iff
-
- FinalWriter is an excellent Page Publishing program, and
- it features an ARexx port. This means that it is possible
- add your own functions such as the bar chart utility.
-
-
- may2.iff
-
- Art Department Professional is (or at least was) the
- premier image processing program. It's ARexx facilities made
- it the ideal batch processing utility.